package net.alegen.android.pizzashop.ui.order;

import net.alegen.android.pizzashop.R;
import net.alegen.android.pizzashop.order.Order;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.telephony.SmsManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class ClientInfoLayoutFragment extends Fragment implements OnClickListener {

	private Button btnOrder;
	private EditText editName;
	private EditText editTelephone;
	
	@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		View v = inflater.inflate(R.layout.client_info_layout, null);
		this.btnOrder = (Button)v.findViewById(R.id.btnOrder);
		this.editName = (EditText)v.findViewById(R.id.editName);
		this.editTelephone = (EditText)v.findViewById(R.id.editTelephone);
		this.btnOrder.setOnClickListener(this);
        return v;
    }

	public void onClick(View v) {		
		try {
			Order.name = this.editName.getText().toString();
			Order.telephone = this.editTelephone.getText().toString();
			this.sendSMS(Order.xml());
			Toast.makeText(ClientInfoLayoutFragment.this.getActivity(), "Your order has been sent: \n" + Order.prettyString(), Toast.LENGTH_LONG).show();
		} catch (Exception e) {
			e.printStackTrace();
		}		
	}
	
	private void sendSMS(String order) {
		SmsManager smsManager = SmsManager.getDefault();
		String number = "0123456789";
		//smsManager.sendTextMessage(number, null, order, null, null);		
	}
}